//
//  HYMovieDateTableViewController.m
//  KaiJing
//
//  Created by lanou on 16/1/13.
//  Copyright © 2016年 HuangZuCui. All rights reserved.
//

#import "HYMovieDateTableViewController.h"
#import "HYMovieDateTableViewCell.h"
#import "HYMovieDateModel.h"
#import "PKRequestManager.h"
#import "HYMovieDateModel.h"
#import <MJExtension.h>
#import "HYMovieTableModel.h"

@interface HYMovieDateTableViewController ()
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) NSMutableArray *tableArray;
@property (nonatomic, strong) HYMovieDateModel *dateModel;
@property (nonatomic, strong) NSMutableDictionary *dataDic;

@end
static NSString *identifier = @"HYMovieDateTableViewController";
@implementation HYMovieDateTableViewController

- (void)setUpData
{
//    NSUUID *uuid = [UIDevice currentDevice].identifierForVendor;
//    NSString *uuidString = uuid.UUIDString;
    NSString *string = [NSString stringWithFormat:@"http://morguo.com/forum.php?mod=viewthread&tid=%@&androidflag=1&appfrom=ios&iosversion=3.13&page=1",_model.tid];
  
    
    [PKRequestManager requestWithUrlString:string parDic:nil method:GET finish:^(NSDictionary *dataDic) {
        
//        NSArray *listArray = dataDic[@"data"][@"list"];
//        _dataArray = [NSMutableArray array];
//        _dataDic = [NSMutableDictionary dictionary];
//        for (NSDictionary *dic in listArray) {
//            NSDictionary *dict = dic[@"moviedata"];
//            HYMovieDateModel *model = [[HYMovieDateModel alloc] init];
//            [model setValuesForKeysWithDictionary:dict];
//            [_dataArray addObject:model];
//        }
        self.dataArray = [HYMovieTableModel mj_keyValuesArrayWithObjectArray:dataDic[@"data"][@"details"]];
        _tableArray = [NSMutableArray array];
        for (NSDictionary *dic in _dataArray) {
            HYMovieTableModel *model = [[HYMovieTableModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [_tableArray addObject:model];
            
        }
        [self.tableView reloadData];
    } error:^(NSError *error) {
        
    }];
    
    
}

- (void)setModel:(HYYingKuMainModel *)model
{
    _model = model;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.rowHeight = 200;
    [self.tableView registerClass:[HYMovieDateTableViewCell class] forCellReuseIdentifier:identifier];
    
    [self setUpData];
    
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return _dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HYMovieDateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    
    
    cell.backgroundColor = kRandomClolor;
    cell.model = _tableArray[indexPath.row];
    SZLog(@"%@",cell.model.author);
    return cell;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
